package com.neusoft.neuiotms.dcam.fixed.converter;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.neusoft.bizcore.web.dto.AbstractConverter;
import com.neusoft.neuiotms.dcam.fixed.dto.MachinePartsBindDTO;
import com.neusoft.neuiotms.dcam.fixed.model.MachinePartsBind;
import com.neusoft.neuiotms.dcam.fixed.repository.MachinePartsBindRepository;

@Component
public class MachinePartsBindConverter extends AbstractConverter<MachinePartsBind, MachinePartsBindDTO> {
    @Autowired
    private MachinePartsBindRepository partsBindRepository;

    @Override
    public MachinePartsBind toModel(final MachinePartsBindDTO dto) {
        final MachinePartsBind model;
        if (dto.isNew()) {
            model = new MachinePartsBind();
        } else {
            model = this.partsBindRepository.getOne(dto.getId());
        }
        model.setPartsName(dto.getPartsName());
        model.setPartsCode(dto.getPartsCode());
        model.setBindName(dto.getBindName());
        model.setBindCode(dto.getBindCode());
        model.setStatus(dto.getStatus());
        return model;
    }

    @Override
    public MachinePartsBindDTO toDTO(final MachinePartsBind model, final boolean forListView) {
        final MachinePartsBindDTO dto = new MachinePartsBindDTO();
        dto.setPartsName(model.getPartsName());
        dto.setPartsCode(model.getPartsCode());
        dto.setBindName(model.getBindName());
        dto.setBindCode(model.getBindCode());
        dto.setStatus(model.getStatus());
        return dto;
    }

}
